﻿using System;
using System.Linq;
using System.Web.UI.WebControls;
using Models;
using System.Data;
using System.Collections.Generic;

public partial class Admin_store_StoreList : AdminBase
{

    private DataTable dc = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        grdbind();
    }

    public void grdbind()
    {
        using (Entities bll = new Entities())
        {
            var Bpl = from p in bll.S_Store_Press.OrderByDescending(p => p.SID) select p;

            if (Sname.Text.Trim() != "")
            {
                Bpl = Bpl.Where(p => p.Sname.Contains(Sname.Text.Trim()));
            }

            AspNetPager1.RecordCount = Bpl.Count();
            this.rptList.DataSource = Bpl.Skip((AspNetPager1.CurrentPageIndex - 1) * AspNetPager1.PageSize).Take(AspNetPager1.PageSize).ToList();  //这里好像一定要Tolist();不然会有点错误；;
            this.rptList.DataBind();

        }
    }

    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {   //当页面页数改变时，执行这个方法；
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        grdbind();
    }


    protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        int id = Convert.ToInt32(((Label)e.Item.FindControl("lb_id")).Text);
        Entities bll = new Entities();
        S_Store model = bll.S_Store.First(p => p.SID == id);
        switch (e.CommandName.ToLower())
        {
            case "ibtnlock":
                if (model.IsLock == true)
                    model.IsLock = false;
                else
                    model.IsLock = true;
                break;
            case "del":
                bll.S_Store.Remove(model);
                break;
        }
        bll.SaveChanges();
        Response.Redirect("StoreList.aspx");

    }


    protected void btnSearch_Click(object sender, EventArgs e)
    {
        grdbind();
    }
}

